import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 123
 * Date: 2023-06-03
 * Time: 20:06
 */
class MyQueue {
    public Stack<Integer> A ;
    public Stack<Integer> B ;

    public MyQueue() {
        this.A = new Stack<>() ;
        this.B = new Stack<>() ;

    }

    public void push(int x) {
        if(this.A.empty() && this.B.empty()){
            this.A.push(x) ;
            return ;
        }
        if(this.A.empty()){
            this.B.push(x) ;
            return ;
        }
        if(this.B.empty()){
            this.A.push(x) ;
            return ;
        }
    }

    public int pop() {
        if(this.A.empty() && this.B.empty()){
            return -1;
        }
        int ret = 0 ;
        if(this.A.empty()){
            int sizeNode = this.B.size()   ;
            for(int i = 0 ; i < sizeNode - 1; i ++ ){
                ret = this.B.pop() ;
                this.A.push(ret) ;
            }
            ret = this.B.pop() ;
        }else if(this.B.empty()){
            int sizeNode = this.A.size() ;
            for(int i = 0 ; i < sizeNode -1 ; i ++){
                ret = this.A.pop() ;
                this.B.push(ret) ;
            }
            ret = this.A.pop() ;
        }
        return ret ;

    }

    public int peek() {
        if(this.A.empty() && this.B.empty()){
            return -1;
        }
        int ret = 0 ;
        if(this.A.empty()){
            int sizeNode = this.B.size()   ;
            for(int i = 0 ; i < sizeNode; i ++ ){
                ret = this.B.pop() ;
                this.A.push(ret) ;
            }

        }else if(this.B.empty()){
            int sizeNode = this.A.size() ;
            for(int i = 0 ; i < sizeNode ; i ++){
                ret = this.A.pop() ;
                this.B.push(ret) ;
            }
        }
        return ret ;


    }


    public boolean empty() {
        if(this.A.empty() && this.B.empty()){
            return true ;
        }
        return false ;
    }
}